package com.qdlc.p2p.quartz.job;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.qdlc.p2p.biz.executer.AbstractExecuter;
import com.qdlc.p2p.biz.executer.ExecuterHelper;
import com.qdlc.p2p.biz.executer.impl.BorrowerRepayNoticeExecuter;
import com.qdlc.p2p.biz.service.BorrowRepaymentService;
import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.util.CollectionUtils;
import com.qdlc.p2p.dal.dto.BorrowRepayment;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.util.SystemConfigs;
import com.qdlc.p2p.quartz.AbstractJob;

/**
 * 还款通知提醒
 *
 * @author wuaj
 * @version 1.1.0.0
 * @since 2016年03月11日
 */
public class DoRepaymentNotice extends AbstractJob {

    @Resource
    BorrowRepaymentService borrowRepaymentService;

    @Override
    protected void process() {
        //还款提醒
        List<BorrowRepayment> todayExpiresRepayments = borrowRepaymentService.findTodayExpiresRepayments();
        if (CollectionUtils.isNotNullOrEmpty(todayExpiresRepayments)) {
            for (BorrowRepayment todayExpiresRepayment : todayExpiresRepayments) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("name", todayExpiresRepayment.getBorrow().getName());
                map.put("period", todayExpiresRepayment.getPeriod());
                map.put("repaymentTime", todayExpiresRepayment.getRepaymentTime());
                map.put("repaymentAccount", todayExpiresRepayment.getRepaymentAccount());
                Global.setTransfer("user", todayExpiresRepayment.getUser());
                Global.setTransfer("repay", map);
                AbstractExecuter repaySuccessExecuter = ExecuterHelper.getExecuter(BorrowerRepayNoticeExecuter.class);
                repaySuccessExecuter.execute(0, todayExpiresRepayment.getUser(), new User(SystemConfigs.ADMIN_ID));
            }
        }
    }
}